// Controller when the main page/view loads
jsApp.controller("SpaCtrl", [ '$scope', function($scope) {
} ]);

// Controller for All Users View
jsApp.controller("UsersCtrl", [ '$scope', 'jsService',
		function($scope, jsService) {
			jsService.getUsers($scope);
		} ]);

// Controller for New User View
jsApp.controller("NewUserCtrl", [ '$scope', 'jsService',
		function($scope, jsService) {

			jsService.getUsers($scope);

			$scope.createNewUser = function() {
				var newuser = {
					'firstname' : $scope.firstname,
					'lastname' : $scope.lastname,
					'address' : $scope.address,
					'email' : $scope.email
				};
				// Call jsService to create a new user
				//
				jsService.createUser(newuser, $scope);

				// Push new user to existing table column
				//
				$scope.users.push(newuser);
				// Reset fields values
				//
				$scope.firstname = '';
				$scope.lastname = '';
				$scope.address = '';
				$scope.email = '';
			};
		} ]);
// Controller for Individual User View
jsApp.controller("UsersByIdCtrl", [ '$scope', 'jsService', '$routeParams',
		function($scope, jsService, $routeParams) {
			jsService.getUser($routeParams.userId, $scope);
		} ]);